package level;

/********************************************************************************
 * May have to store Terrain as a 2d array allowing for on the fly creation and *
 * destruction of terrain.                                                      *
 ********************************************************************************/

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import entity.misc.Entrance;
import entity.misc.Exit;
import entity.terrain.Terrain;

/**
 * Controls the storing of the terrain data, handles the creation and destruction of
 * terrain.
 * 
 * @author Neil Cowzer
 */
public class Map {
	/** The x-coordinate of the start point */
	private int startX;
	//@ invariant (* startX is within bounds *);
	
	/** The y-coordinate of the start point */
	private int startY;
	//@ invariant (* startY is within bounds *);
	
	/** The x-coordinate of the end point */
	private int endX;
	//@ invariant (* endX is within bounds *);
	
	/** The y-coordinate of the end point */
	private int endY;
	//@ invariant (* endY is within bounds *);
	
	/** The terrain of the Level. */
	private Terrain terrain;
	/*@ invariant
		terrain != null
		&&
		(\forall int i; 0 <= i && i < terrain.length;
		; terrain[i] != null &&
		terrain[i].getParent() == this);
	@*/
	
	private Entrance entrance;
	private Exit exit;
	/**
	 *  Create an instance of Map.
	 *  
	 * @param startX the x-coordinate of the start point
	 * @param startY the y-coordinate of the start point
	 * @param endX the x-coordinate of the end point
	 * @param endY the y-coordinate of the end point
	 */
	/*@	requires (* startX...endY are within bounds *) && terrain != null; 
	  	assignable endX && endY && startX && startY && terrain;
	@*/
	public Map(int startX, int startY, int endX, int endY, Terrain terrain, Entrance entrance, Exit exit){
		this.endX = endX;
		this.endY = endY;
		this.startX = startX;
		this.startY = startY;
		this.terrain = terrain;
		this.entrance = entrance;
		this.exit = exit;
	}
	
	/**
	 * Retreive the Exits x-coordinate
	 * 
	 * @return the x-coordinate of the endpoint
	 */
	public /*@ pure @*/ int getEndX() {
		return endX;
	}

	/**
	 * Retreive the Exits y-coordinate
	 * 
	 * @return the y-coordinate of the endpoint
	 */
	public /*@ pure @*/ int getEndY() {
		return endY;
	}

	/**
	 * Retreive the Start x-coordinate
	 * 
	 * @return the x-coordinate of the endpoint 
	 */
	public /*@ pure @*/ int getStartX() {
		return startX;
	}

	/**
	 * Retreive the Start y-coordinate
	 * 
	 * @return the y-coordinate of the endpoint
	 */
	public /*@ pure @*/ int getStartY() {
		return startY;
	}
	
	/**
	 * Retrive the Terrain.
	 * 
	 * @return an array of the Terrain
	 */
	public /*@ pure @*/ Terrain getTerrain(){
		return terrain;
	}
	
	public /*@ pure @*/ Exit getExit(){
		return exit;
	}
	
	public /*@ pure @*/ Entrance getEntrance(){
		return entrance;
	}
	
	
	/**
	 * Draw the Terrain to the screen.
	 * 
	 * @param g
	 */
	public void draw(Graphics g){
			terrain.draw(g);
			
			exit.update();
			exit.draw(g);
			
			entrance.update();
			entrance.draw(g);
	}

}
